/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-04-19
 * Time: 19:43
 */
public class MyQueue {
    static class ListNode {
        public ListNode next;
        public int val;
        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode head;
    public ListNode last;
    private int usedSize;
    public void offer(int val) {
        ListNode node = new ListNode(val);
        if(head == null) {
            head = node;
        } else {
            last.next = node;
        }
        last = node;
        usedSize ++;
    }

    public int poll() {
        if(head == null) {
            return -1;
        } else if (head.next == null) {
            int temp = head.val;
            head = null;
            last = null;
            usedSize --;
            return temp;
        } else {
            int temp = head.val;
            head = head.next;
            usedSize --;
            return temp;
        }
    }
    public int peek() {
        if(head == null) {
            return -1;
        }
        return head.val;
    }

    public int getUsedSizeSize() {
        return usedSize;
    }

    public boolean isEmpty() {
        if(head == null && last ==null) {
            return true;
        }
        return false;
    }


}
